﻿using EOrm;
using LeanApp.Bll;
using LeanApp.General;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using SkiaSharp;
using System.Windows;

namespace LeanApp
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// 启动重写
        /// </summary>
        /// <param name="e">启动参数</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            ConfigOverwrite.OverwriteConfig();
            LiveCharts.Configure(config =>
            {
                config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('汉'));

            });
            EOrmBase.SetOrderMethod(false);
            EntityTypeMapper.TypeMap();
            MainWindow mainWindow = new MainWindow();
            RegisterBll bll = new RegisterBll();
            mainWindow.Hide();
            if (bll.IsRegister()) // 假设这是你的条件检查
            {
                mainWindow.Show();
            }
            else
            {
                bool registerResult = bll.RunRegister();
                if (registerResult)
                {
                    mainWindow.Show();
                }
                else
                {
                    MessageBox.Show("当前设备未注册，程序即将退出");
                    this.Shutdown(); // 停止应用程序
                    return; // 确保退出方法，不继续执行后续代码
                }
            }
        }
    }
}
